rm(list=ls())
library(foreign)
library(ggplot2) 
library(gridExtra)
library(knitr)
library(grid)
library(dplyr)
library(forcats)
library(haven)
library(grid)
library(gridExtra)
library(ggtext)
library(viridis)

theme_results <- theme_bw(base_size = 19) +
  theme(text=element_text(family="Times",
                          size = 19),
        axis.text.x = element_text(size = 19, color = "black"),
        axis.text.y = element_text(size = 15, color = "black",angle=0),
        axis.title.y = element_text(size = 19, color = "black"),
        axis.title.x = element_text(size = 17, color = "black"),
        legend.position = "bottom",
        legend.key.size = unit(1.2, "cm"),
        legend.text = element_text(size = 17),
        legend.title = element_text(size = 1),
        panel.grid.major.y = element_blank(),
        panel.grid.minor.y = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        strip.background = element_rect(fill = "white"))



palette2 <- c("black", "gray", "blue", "#0098DB")
palette3<- c("black","gray","blue")
palette_twolines <- c("black", "gray")
palette6<- c("#1B5E20", "#388E3C", "#66BB6A", "#6A1B9A", "#8E24AA", "#E1BEE7")
palette_facet <- c("black", "dodgerblue2", "grey40")


setwd("~/Desktop/...")




#ALL VAR Data and labels ----
allvar <- read_dta("allvar.dta")

allvar$allvar <- factor(allvar$var2,
                            levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                            labels = c("Joy",
"Pride",
"Sadness",
"Hostility",
"Fear",
"Disgust",
"Anger", 
"Disabled",
"Jewish",
"Asian",
"Black",
"LGB",
"Muslim",
"Intersex",
"Transgender",
"Roma",
"Jehova's Witness",
"PCA coworkers",
"PCA refugees",
"Money spent in refugees could be\n better spent in Germans (inv)",
"Refugees are more to\n blame for crime (inv)",
"Refugees will increase\n likelihood of terrorist attack (inv)",
"Refugees should be granted\n asylum and residence rights",
"Quantity donated",
"Makes donation",
"Democracy preferrable"))


allvar$facet <- factor(allvar$Facet,
                    levels = c(1,3,2,4),
                    labels = c("Emotions",
                               "Attitudes toward refugees",
                               "Comfort having minorities as coworkers",
                               "Democracy and donations"))


allvar$controls <- factor(allvar$Controls,
                         levels = c(0,1),
                         labels = c("No controls",
                                    "Controls"))


  allvar$no_controls <- factor(allvar$Controls,
                                levels = c(0),
                                labels = c("No controls"))
                        

# FIGURE 2
  allvar_nocontrol <- allvar[which( allvar$Controls== "0"),]
  plot_allvar_nocontrol <- allvar_nocontrol  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef,
               color = as.factor(pca))) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Differences between treatment\n and control group (standardized)") +  xlab("") +
    scale_color_manual(name = "",values = c("black", "blue") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_wrap(~facet, 
               scales="free_y", ncol=1) +
    theme_results +
    coord_flip() +
    theme(legend.position = "none")
  plot_allvar_nocontrol
  

  
  
  # FIGURE D2 in Appendix
  allvar_controls <- allvar[which( allvar$Controls== "1"),]
  plot_allvar_controls<- allvar_controls %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef,
               color = as.factor(pca))) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Differences between treatment\n and control group (standardized) with controls") +  xlab("") +
    scale_color_manual(name = "",values = c("black", "blue") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_wrap(~facet, 
               scales="free_y", ncol=1) +
    theme_results +
    coord_flip() +
    theme(legend.position = "none")
  plot_allvar_controls
  

  
  
  
  
  
  
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # #  #  #  #  #  #  #  # 
  

  #ALL VAR  HTE AGE Data and labels ----
  ageallvar <- read_dta("hte_age.dta")
  
  ageallvar$interaction <- factor(ageallvar$var,
                                  levels = c("treat_age_2", "treat_age_3", "treat_age_4","treat_age_5", "treatment"),
                                  labels = c("Treat x 25-34 yo",
                                             "Treat x 35-44 yo",
                                             "Treat x 45-54 yo",
                                             "Treat x 55+ yo",
                                             "AGE"))
  ageallvar$facet2 <- factor(ageallvar$Facet2,
                                levels = c(2,1),
                                labels = c("Interaction", "Group estimate"))
  ageallvar$allvar <- factor(ageallvar$var2,
                             levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                             labels = c("Joy",
                                        "Pride",
                                        "Sadness",
                                        "Hostility",
                                        "Fear",
                                        "Disgust",
                                        "Anger", 
                                        "Disabled",
                                        "Jewish",
                                        "Asian",
                                        "Black",
                                        "LGB",
                                        "Muslim",
                                        "Intersex",
                                        "Transgender",
                                        "Roma",
                                        "Jehova's Witness",
                                        "PCA coworkers",
                                        "PCA refugees",
                                        "Money spent in refugees could be\n better spent in Germans (inv)",
                                        "Refugees are more to\n blame for crime (inv)",
                                        "Refugees will increase\n likelihood of terrorist attack (inv)",
                                        "Refugees should be granted\n asylum and residence rights",
                                        "Quantity donated",
                                        "Makes donation",
                                        "Democracy preferrable"))
  
  
  ageallvar$facet <- factor(ageallvar$Facet,
                            levels = c(1,3,2,4),
                            labels = c("Emotions",
                                       "Attitudes toward refugees",
                                       "Comfort having minorities as coworkers",
                                       "Democracy and donations"))
  
  
  ageallvar$controls <- factor(ageallvar$Controls,
                               levels = c(0,1),
                               labels = c("No controls",
                                          "Controls"))
  
  ageallvar$group <- factor(ageallvar$Group,
                               levels = c(1,2,3,4,5,0),
                               labels = c("18-24",
                                          "25-34",
                                          "35-44",
                                          "45-54",
                                          "55+",
                                          "18-24 vs Age group"))
  
  
  ageallvar$no_controls <- factor(ageallvar$Controls,
                                  levels = c(0),
                                  labels = c("No controls"))
  
  
  
 
  
  # FIGUGRE E.3 IN Appendix 
  ageallvar_nocontrol_emotions <- ageallvar[which(ageallvar$Controls== "0" & ageallvar$Facet== "1") ,]
  plot_ageallvar_nocontrol_emotions <- ageallvar_nocontrol_emotions  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color=group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~interaction+facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_ageallvar_nocontrol_emotions

  
  # Figure E.4. in Appendix--------
  ageallvar_nocontrol_work<- ageallvar[which(ageallvar$Controls== "0" & ageallvar$Facet== "2") ,]
  plot_ageallvar_nocontrol_work <- ageallvar_nocontrol_work  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color=group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~interaction+facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_ageallvar_nocontrol_work

  
  # Figure E.5 in Appendix --------    
  ageallvar_nocontrol_ref<- ageallvar[which(ageallvar$Controls== "0" & ageallvar$Facet== "3") ,]
  plot_ageallvar_nocontrol_ref <- ageallvar_nocontrol_ref  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color=group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~interaction+facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_ageallvar_nocontrol_ref

  
  # Figure E.6 in Appendix --------    
  ageallvar_nocontrol_demo<- ageallvar[which(ageallvar$Controls== "0" & ageallvar$Facet== "4") ,]
  plot_ageallvar_nocontrol_demo <- ageallvar_nocontrol_demo  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color=group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~interaction+facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_ageallvar_nocontrol_demo

  
  
   #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # #  #  #  #  #  #  #  # 
  
  #ALL VAR  HTE HIGH LOW POLINT Data and labels ----
  polintallvar <- read_dta("hte_hlpolint.dta")
  
  polintallvar$interaction <- factor(polintallvar$var,
                                  levels = c("treat_hlpolint"),
                                  labels = c("Treat x Low political interest"))
  
  polintallvar$facet2 <- factor(polintallvar$Facet2,
                                 levels = c(1,2),
                                 labels = c("Estimate",
                                            "Difference in the Effect of the Treatment"))
  
  polintallvar$allvar <- factor(polintallvar$var2,
                             levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                             labels = c("Joy",
                                        "Pride",
                                        "Sadness",
                                        "Hostility",
                                        "Fear",
                                        "Disgust",
                                        "Anger", 
                                        "Disabled",
                                        "Jewish",
                                        "Asian",
                                        "Black",
                                        "LGB",
                                        "Muslim",
                                        "Intersex",
                                        "Transgender",
                                        "Roma",
                                        "Jehova's Witness",
                                        "PCA coworkers",
                                        "PCA refugees",
                                        "Money spent in refugees could be\n better spent in Germans (inv)",
                                        "Refugees are more to\n blame for crime (inv)",
                                        "Refugees will increase\n likelihood of terrorist attack (inv)",
                                        "Refugees should be granted\n asylum and residence rights",
                                        "Quantity donated",
                                        "Makes donation",
                                        "Democracy preferrable"))
  
  
  polintallvar$facet <- factor(polintallvar$Facet,
                            levels = c(1,3,2,4),
                            labels = c("Emotions",
                                       "Attitudes toward refugees",
                                       "Comfort having minorities as coworkers",
                                       "Democracy and donations"))
  
  
  polintallvar$controls <- factor(polintallvar$Controls,
                               levels = c(0,1),
                               labels = c("No controls",
                                          "Controls"))
  
  polintallvar$group <- factor(polintallvar$Group,
                               levels = c(1,2,0),
                               labels = c("Low interest","High interest", "Low vs High"))
  
  polintallvar$no_controls <- factor(polintallvar$Controls,
                                  levels = c(0),
                                  labels = c("No controls"))
  
  

  
  # FIGURE 3 ----
  polintallvar_nocontrol2 <- polintallvar[which( polintallvar$Controls== "0"),]
  plot_polintallvar_nocontrol2 <- polintallvar_nocontrol2  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color = group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_polintallvar_nocontrol2

  
  
 
  
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # #  #  #  #  #  #  #  # 

  #ALL VAR  HTE IDEOLOGY continua Data and labels ----
  hte_leftright <- read_dta("hte_leftright.dta")
  
  hte_leftright$interaction <- factor(hte_leftright$var,
                                        levels = c("treat_scale"),
                                        labels = c("Treat x Left-Right Self-placement"))
  
  hte_leftright$facet2 <- factor(hte_leftright$Facet2,
                                   levels = c(1,2),
                                   labels = c("Estimate",
                                              "Difference in the Effect of the Treatment"))
  
  
  hte_leftright$group <- factor(hte_leftright$Group,
                                  levels = c(1,2,0),
                                  labels = c("Right >5","Left<5", "Right vs Left"))
  
  hte_leftright$allvar <- factor(hte_leftright$var2,
                                   levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                                   labels = c("Joy",
                                              "Pride",
                                              "Sadness",
                                              "Hostility",
                                              "Fear",
                                              "Disgust",
                                              "Anger", 
                                              "Disabled",
                                              "Jewish",
                                              "Asian",
                                              "Black",
                                              "LGB",
                                              "Muslim",
                                              "Intersex",
                                              "Transgender",
                                              "Roma",
                                              "Jehova's Witness",
                                              "PCA coworkers",
                                              "PCA refugees",
                                              "Money spent in refugees could be\n better spent in Germans (inv)",
                                              "Refugees are more to\n blame for crime (inv)",
                                              "Refugees will increase\n likelihood of terrorist attack (inv)",
                                              "Refugees should be granted\n asylum and residence rights",
                                              "Quantity donated",
                                              "Makes donation",
                                              "Democracy preferrable"))
  
  
  hte_leftright$facet <- factor(hte_leftright$Facet,
                                  levels = c(1,3,2,4),
                                  labels = c("Emotions",
                                             "Attitudes toward refugees",
                                             "Comfort having minorities as coworkers",
                                             "Democracy and donations"))
  
  
  hte_leftright$controls <- factor(hte_leftright$Controls,
                                     levels = c(0,1),
                                     labels = c("No controls",
                                                "Controls"))
  
  
  hte_leftright$no_controls <- factor(hte_leftright$Controls,
                                        levels = c(0),
                                        labels = c("No controls"))
  
  
  
 
  
  # FIGURE 4 ----
  hte_leftright_nocontrol2 <-  hte_leftright[which(  hte_leftright$Controls== "0"),]
  plot_hte_leftright_nocontrol2 <-  hte_leftright_nocontrol2  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color = group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_hte_leftright_nocontrol2

  
  
  
  
  
  
  
  
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # 
  #ALL VAR  HTE gender Data and labels ----
  genderallvar <- read_dta("hte_gender.dta")
  
  
  genderallvar$interaction <- factor(genderallvar$var,
                                        levels = c("woman_treat"),
                                        labels = c("Treat x Gender (Woman)"))
  
  genderallvar$group <- factor(genderallvar$Group,
                                     levels = c(1,2,0),
                                     labels = c("Women","Men", "Women vs Men"))
  
  genderallvar$allvar <- factor(genderallvar$var2,
                                   levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                                   labels = c("Joy",
                                              "Pride",
                                              "Sadness",
                                              "Hostility",
                                              "Fear",
                                              "Disgust",
                                              "Anger", 
                                              "Disabled",
                                              "Jewish",
                                              "Asian",
                                              "Black",
                                              "LGB",
                                              "Muslim",
                                              "Intersex",
                                              "Transgender",
                                              "Roma",
                                              "Jehova's Witness",
                                              "PCA coworkers",
                                              "PCA refugees",
                                              "Money spent in refugees could be\n better spent in Germans (inv)",
                                              "Refugees are more to\n blame for crime (inv)",
                                              "Refugees will increase\n likelihood of terrorist attack (inv)",
                                              "Refugees should be granted\n asylum and residence rights",
                                              "Quantity donated",
                                              "Makes donation",
                                              "Democracy preferrable"))
  
  
  genderallvar$facet <- factor(genderallvar$Facet,
                                  levels = c(1,3,2,4),
                                  labels = c("Emotions",
                                             "Attitudes toward refugees",
                                             "Comfort having minorities as coworkers",
                                             "Democracy and donations"))
 
   genderallvar$facet2 <- factor(genderallvar$Facet2,
                               levels = c(1,2),
                               labels = c("Estimate",
                                          "Difference in the Effect of the Treatment"))
  
  
  genderallvar$controls <- factor(genderallvar$Controls,
                                     levels = c(0,1),
                                     labels = c("No controls",
                                                "Controls"))
  
  
  genderallvar$no_controls <- factor(genderallvar$Controls,
                                        levels = c(0),
                                        labels = c("No controls"))
  
  
  
 
  #### FIGURE E.7 in Appendix
  genderallvar_nocontrol2 <- genderallvar[which( genderallvar$Controls== "0"),]
  plot_genderallvar_nocontrol2 <- genderallvar_nocontrol2  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color = group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_genderallvar_nocontrol2

  
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # #  #  #  #  #  #  #  # 
  
  
  # FIGURE E.8 in Appendix---
  collegeallvar <- read_dta("hte_college.dta")
  

  
  collegeallvar$group <- factor(collegeallvar$Group,
                               levels = c(1,2,0),
                               labels = c("College","Not College", "College vs Not College"))
  
  collegeallvar$allvar <- factor(collegeallvar$var2,
                                levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                                labels = c("Joy",
                                           "Pride",
                                           "Sadness",
                                           "Hostility",
                                           "Fear",
                                           "Disgust",
                                           "Anger", 
                                           "Disabled",
                                           "Jewish",
                                           "Asian",
                                           "Black",
                                           "LGB",
                                           "Muslim",
                                           "Intersex",
                                           "Transgender",
                                           "Roma",
                                           "Jehova's Witness",
                                           "PCA coworkers",
                                           "PCA refugees",
                                           "Money spent in refugees could be\n better spent in Germans (inv)",
                                           "Refugees are more to\n blame for crime (inv)",
                                           "Refugees will increase\n likelihood of terrorist attack (inv)",
                                           "Refugees should be granted\n asylum and residence rights",
                                           "Quantity donated",
                                           "Makes donation",
                                           "Democracy preferrable"))
  
  
  collegeallvar$facet <- factor(collegeallvar$Facet,
                               levels = c(1,3,2,4),
                               labels = c("Emotions",
                                          "Attitudes toward refugees",
                                          "Comfort having minorities as coworkers",
                                          "Democracy and donations"))
  
  collegeallvar$facet2 <- factor(collegeallvar$Facet2,
                                levels = c(1,2),
                                labels = c("Estimate",
                                           "Difference in the Effect of the Treatment"))
  
  
  collegeallvar$controls <- factor(collegeallvar$Controls,
                                  levels = c(0,1),
                                  labels = c("No controls",
                                             "Controls"))
  
  
  collegeallvar$no_controls <- factor(collegeallvar$Controls,
                                     levels = c(0),
                                     labels = c("No controls"))
  
  
  
  #  College --------
  ####  ###
  collegeallvar_nocontrol2 <- collegeallvar[which( collegeallvar$Controls== "0"),]
  plot_collegeallvar_nocontrol2 <- collegeallvar_nocontrol2  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color = group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_collegeallvar_nocontrol2

  
  
  
  
  
  
  
  
  
  
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # #  #  #  #  #  #  #  # 
  
  #ALL VAR  HTE RELIGIOUS Data and labels ----
  religiousallvar <- read_dta("hte_religious.dta")
  
  
  
  religiousallvar$group <- factor(religiousallvar$Group,
                                levels = c(1,2,0),
                                labels = c("Religious","Not religious", "Religious vs not religious"))
  
  religiousallvar$allvar <- factor(religiousallvar$var2,
                                 levels = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,23,22,21,20,19,26,25,24),
                                 labels = c("Joy",
                                            "Pride",
                                            "Sadness",
                                            "Hostility",
                                            "Fear",
                                            "Disgust",
                                            "Anger", 
                                            "Disabled",
                                            "Jewish",
                                            "Asian",
                                            "Black",
                                            "LGB",
                                            "Muslim",
                                            "Intersex",
                                            "Transgender",
                                            "Roma",
                                            "Jehova's Witness",
                                            "PCA coworkers",
                                            "PCA refugees",
                                            "Money spent in refugees could be\n better spent in Germans (inv)",
                                            "Refugees are more to\n blame for crime (inv)",
                                            "Refugees will increase\n likelihood of terrorist attack (inv)",
                                            "Refugees should be granted\n asylum and residence rights",
                                            "Quantity donated",
                                            "Makes donation",
                                            "Democracy preferrable"))
  
  
  religiousallvar$facet <- factor(religiousallvar$Facet,
                                levels = c(1,3,2,4),
                                labels = c("Emotions",
                                           "Attitudes toward refugees",
                                           "Comfort having minorities as coworkers",
                                           "Democracy and donations"))
  
  religiousallvar$facet2 <- factor(religiousallvar$Facet2,
                                 levels = c(1,2),
                                 labels = c("Estimate",
                                            "Difference in the Effect of the Treatment"))
  
  
  religiousallvar$controls <- factor(religiousallvar$Controls,
                                   levels = c(0,1),
                                   labels = c("No controls",
                                              "Controls"))
  
  
  religiousallvar$no_controls <- factor(religiousallvar$Controls,
                                      levels = c(0),
                                      labels = c("No controls"))
  
  
  
  # FIGURE E.9. in Appendix --------
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  # #  #  #  #  #  #  #  # 
  
  
  religiousallvar_nocontrol2 <- religiousallvar[which( religiousallvar$Controls== "0"),]
  plot_religiousallvar_nocontrol2 <- religiousallvar_nocontrol2  %>%
    mutate(lower90 = coef - 1.645*stderr) %>%
    mutate(upper90 = coef + 1.645*stderr) %>%
    mutate(pca = ifelse(var2 %in% c(18,23), 1, 0)) %>%
    mutate(order = pca + coef) %>%
    mutate(allvar = fct_reorder(allvar, order)) %>%
    ggplot(aes(x = as.factor(allvar), y = coef, color = group)) +   
    geom_point(size = 2.5 ,position = position_dodge(0.35)) +
    geom_errorbar(aes(ymax = ci_upper, ymin = ci_lower), width = 0, size = .5, position = position_dodge(width = 0.35)) +
    geom_errorbar(aes(ymax = lower90, ymin = upper90), width = 0, size = 1, position = position_dodge(width = 0.35)) +
    ylab("Coefficients of the effect of exposure to Stolpersteine (standardized)") +  xlab("") +
    #    scale_color_manual(name = "",values = c("black", "blue", "gray", "orange") )+
    geom_hline(yintercept = 0, 
               linetype = 2, color = "black", alpha = .4) + 
    facet_grid(facet~facet2,  scales="free_y") +
    theme_results +
    coord_flip() +
    theme(strip.text = element_text(size=12),
          axis.text.x = element_text(size = 12, color = "black"),
          axis.text.y = element_text(size = 12, color = "black",angle=0),
          legend.text = element_text(size = 10))
  plot_religiousallvar_nocontrol2

  
  
  
  
  
  